def count():
#把指定文件内容转换为小写的单词列表
    file = '/home/python/project/pro1/sample.txt'
    with open(file) as f:
        list_old = f.read().lower().split()

#统计列表各单词出现次数，转换为字典
    dict_old = {}
    for i in list_old:
        if i not in dict_old:
            dict_old[i] = 0
        dict_old[i] += 1

#对字典排序（按照单词出现次数排序）
    list_sort = sorted(dict_old,key=lambda x:dict_old[x],reverse=True)

#统计列表前10单词
    list_top10=list()
    for i in list_sort:
        if str(i) == str(list_sort[10]):
            break
        else:
            list_top10.append(i)
            
#根据列表前10单词生成字典前十
    dict_top10 = { i:dict_old[i] for i in list_top10 }
    return dict_top10

# 效率差了点,可以考虑有么有优化的方法